/**
 * Created by chenkuan on 2017/3/31.
 */
var path = require('path');
var rf=require("fs");
var config = require('../config/config');
var utils={
    getSQL:function (modelPath,SQL_FILE_NAME) {
        var filepath = path.resolve("../config/",modelPath||"./",config.path.sql_file_path,SQL_FILE_NAME);
        if(filepath.indexOf('.sql')!=filepath.length-4)filepath+=".sql";
        var sql=rf.readFileSync(filepath,"utf-8");
        return sql
    },
    getFuncArgs:function(func) {
        // 首先匹配函数括弧里的参数
        var args = func.toString().match(/function\s.*?\(([^)]*)\)/)[1];

        // 分解参数成数组
        return args.split(",").map(function(arg) {
            // 去空格和内联注释
            return arg.replace(/\/\*.*\*\//, "").trim();
        }).filter(function(arg) {
            // 确保没有undefineds
            return arg;
    });
}
};
module.exports = utils;